<template>
  <div class="address-list">
		<JdNavbar title='地址栏' rightText=''></JdNavbar>

		<van-address-list
			:list="list"
			v-model="list._id"
			default-tag-text="默认"
			@add="onAdd"
			@edit="onEdit"
		/>
  </div>
</template>

<script>
import { JdNavbar } from '@/components'
import { Toast } from 'vant'

export default {
  name: 'addresslist',
	components: {
		JdNavbar
	},

	data() {
		return {
			list: []
		}
	},

	methods: {
		init () {
			this.$api.getAddr({}).then(res => {
				console.log( res.data )
				this.list = this.listTranfer(res.data)
			})
		},

		listTranfer(list){
      return list.map(item=>(
        {
          id: item._id,
          name: item.name,
          tel: item.tel,
          address: item.address,
          isDefault: item.isDefault,
        }
      ))
    },

		onAdd() {
			this.$router.push('/addr/add')
		},

		onEdit(item, index) {
			Toast('编辑地址:' + index)
		},

	},

	mounted () {
		this.init()
	}
}
</script>

<style lang="scss" scoped>

</style>